package cn.wolfcode.crm.web.controller;


import cn.wolfcode.crm.domain.FormalCustomer;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.ICustomerService;
import cn.wolfcode.crm.service.IFormalCustomerService;
import cn.wolfcode.crm.service.ISystemdictionaryService;
import cn.wolfcode.crm.util.UserContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Date;

@RequestMapping("formalCustomer")
@Controller
public class FormalCustomerController {
    @Autowired
    private IFormalCustomerService formalCustomerService;
    @Autowired
    private ICustomerService customerService;
    @Autowired
    private ISystemdictionaryService itemService;

    @RequestMapping("list")
    public String list(Model model,@ModelAttribute("qo") QueryObject qo) {
        model.addAttribute("pageInfo", formalCustomerService.queryForList(qo));
        model.addAttribute("cms", customerService.list());//客户
        model.addAttribute("curriculum", itemService.queryItemForCurriculum());//课程
        return "formalCustomer/list";
    }

    @RequestMapping("save")
    public String save(FormalCustomer entity) {
        customerService.updateFormal(entity.getCustomer());
        entity.setVdate(new Date());
        entity.setSeller(UserContext.getCurrentUser());
        formalCustomerService.save(entity);
        return "redirect:/formalCustomer/list.do";
    }
}
